﻿
// ZhengTuToolsDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "ZhengTuTools.h"
#include "ZhengTuToolsDlg.h"
#include "afxdialogex.h"
#include "ZTOpt\ZTOpt.h"
#include "GlobalFiles\ZLog.h"
#include "DmEx\DmOptEx.h"  

#ifdef _DEBUG 
#define new DEBUG_NEW
#endif 


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

// 对话框数据
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CZhengTuToolsDlg 对话框


CZhengTuToolsDlg* CZhengTuToolsDlg::global_pDlg = NULL;

CZhengTuToolsDlg::CZhengTuToolsDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CZhengTuToolsDlg::IDD, pParent)
	, m_ZThWnd(_T(""))
	, m_LogString(_T(""))
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	global_pDlg = this;
	m_bRunning = false;
	m_bAllwaysRunning = false;
}

void CZhengTuToolsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_ZThWnd);
	DDX_Text(pDX, IDC_EDIT2, m_LogString);
}

BEGIN_MESSAGE_MAP(CZhengTuToolsDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_STARTBTN, &CZhengTuToolsDlg::OnBnClickedStartbtn)
	ON_BN_CLICKED(IDC_BUTTON_NEXT, &CZhengTuToolsDlg::OnBnClickedButtonNext)
	ON_BN_CLICKED(IDC_BUTTON_GO, &CZhengTuToolsDlg::OnBnClickedButtonGo)
END_MESSAGE_MAP()


// CZhengTuToolsDlg 消息处理程序

BOOL CZhengTuToolsDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void CZhengTuToolsDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CZhengTuToolsDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CZhengTuToolsDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void CZhengTuToolsDlg::OnBnClickedStartbtn()
{
// 	VARIANT x, y;
// 	x.vt = VT_I4;
// 	y.vt = VT_I4;
// 	x.iVal = 5;
// 	y.iVal = 5;
// 	ASSERT(dm.ClientToScreen((long)m_hWnd, &x, &y));
// 	CString tmp;
// 	tmp.Format(_T("%d,%d"), x.iVal, y.iVal);
// 	AfxMessageBox(tmp);
// 
// 	UpdateData(TRUE);
 	m_CalcCenter.Run();


	//ttt
	//
// 	AfxMessageBox(_T("5秒之后开始运行,自动识别装备信息，识别的信息保存在log文件夹中，屏幕分辨率和游戏分辨率都是1280*720,游戏色彩模式为16色"));
// 	Sleep(5000);
// 	g_dmEx.LeftClick();
// 
// 	CString sStr;
// 	for ( int iRow=0; iRow<6; iRow++)
// 	{
// 		for (int iCol=0; iCol<7; iCol++)
// 		{
// 			EquipmentInfo equInfo = g_ZTOpt.HuoQu_WuPinXinXi(iRow, iCol);
// 			if (equInfo.m_IsEmpty)
// 			{
// 				sStr.Format(_T("行列:%d,%d白色装备或者不是装备"), equInfo.m_Row, equInfo.m_Col);
// 			}
// 			else
// 			{
// 				sStr.Format(_T("行列:%d,%d--颜色：%s--等级:%d"), 
// 					equInfo.m_Row, equInfo.m_Col, g_EquipmentColorName[equInfo.m_EquipmentColor], equInfo.m_EquipmentLevel);
// 			}
// 
// 			g_writeLog(sStr);
// 		}
// 	}

	//	int iJiaGe = g_ZTOpt.Get_ZhuangJiaGe(EC_Purple, 101);
	//	g_ZTOpt.DaKai_QiuGouHang();
	//	g_ZTOpt.DaKai_BaoGuo(); //OK
	//	g_ZTOpt.DaKai_KuaiSuMaiWu();
	//
	//ttt
}

void CZhengTuToolsDlg::OnBnClickedButtonNext()
{
	m_bRunning = true;
}

void CZhengTuToolsDlg::OnBnClickedButtonGo()
{
	m_bAllwaysRunning = true;
}

CZhengTuToolsDlg* CZhengTuToolsDlg::GetMainDialog()
{
	return global_pDlg;
}

void CZhengTuToolsDlg::Write_Log( const CString& log )
{
	m_LogString += log + _T("\n");
	UpdateData(FALSE);
	if (m_bAllwaysRunning == true)
		return;

	if (m_bRunning == false)
	{
		//做消息循环 直到允许向下执行
		MSG  msg;  
		if (PeekMessage(&msg,(HWND)NULL, 0, 0, PM_REMOVE))  
		{
			::SendMessage(msg.hwnd, msg.message, msg.wParam, msg.lParam);    
		}
	}
	m_bRunning = false;
}
